define(function(require,exports,module) {
    var myPub = require('./public');

    var oGoodsShowBox = $('.js_goodsShowBox');
    var oCategorysGroupBox = $('.js_categorys_group');          // 分类容器

    // 获取产品数据的路径
    var goodsDateUrl = 'static_v4/js/dataJson/goodsData.json';

    module.exports = {
        init:function(data,names){

            // 产品懒加载  异步加载 调用这个
            myPub.lazLoadingImgEchoAbs(oCategorysGroupBox[0]);

            // categorysGoods.ScrollLoad()
            checkEqu.ChangeAHerf(oCategorysGroupBox.find('li a'))
            //categorysGoods.getDataList()
        }
    };

    var categorysGoods = {
        loadOff: [false],       // 加载开关
        getDataList: function (fn) {
            var _this = this;
            G_JSON_GET(goodsDateUrl,{
                // "maxLimit":maxLimit
            },function (data) {
                // console.log(data.goodsNew.length);
                var dataJson = data.goodsNew;
                if( data.status == "success") {
                    // _this.GoodsLiHtml(dataJson) ;
                    if(fn)fn()
                }
            }, function () {
                // start
            }, function () {
                // end
                // myPub.lazLoadingImgEchoAbs(oCategorysGroupBox[0]);
            });
        },

        GoodsLiHtml:function (dataJson) {
            var shtmlLi = ''
            for (var i=0; i<dataJson.length; i++) {
                shtmlLi += '<li>'+
                        '<a class="BoxSelf" _href="goods_detail.html">'+
                            '<figure>'+
                                '<img class="js_lazyImg" data-echo="static_v4/image/flower5.jpg" src="static_v4/image/loadImg.jpg">'+
                            '</figure>'+
                            '<aside class="priceArea VBox Bflex1">'+
                                '<div class="Bflex1 priceArea_name">'+
                                    '<h4>山西运城有机库尔勒</h4>'+
                                    '<p class="smallFont_tip">原味生鲜 750g/盒</p>'+

                                '</div>'+
                                '<div class="priceArea_price">'+
                                    '<i class="tip-info">限时立减150</i>'+
                                    '<p class="HBox priceAreaBox">'+
                                        '<span class="goodsPriceOld">￥29.00</span>'+
                                        '<span class="goodsPrice">￥29.00</span>'+
                                    '</p>'+
                                '</div>'+
                            '</aside>'+
                        '</a>'+
                    '</li>';
            }
            var $HtmlLi = $(shtmlLi);
            checkEqu.ChangeAHerf($HtmlLi.find('a'));
            oCategorysGroupBox.find('.js_goodsList').append($HtmlLi);
            myPub.lazLoadingImgEchoAbs(oCategorysGroupBox[0]);
        },

        ScrollLoad: function () {
            var scrollTime = null;
            var minScrHeight = 300;
            oGoodsShowBox.on('scroll', function () {
                // 滚动页面距离底部300像素 延迟150毫秒加载数据
                clearTimeout(scrollTime);
                scrollTime = setTimeout(function() {
                    if(oGoodsShowBox[0].scrollHeight - oGoodsShowBox.scrollTop() - oGoodsShowBox.height() < minScrHeight) {
                        // categorysGoods.getDataList()
                    }
                },150);
            })
        }
    }

    var checkEqu = {
        hrefName: [BASE + '/h/goodspay/goodsView/', 'sf://goodsDetail?goodsSn='],
        ChangeAHerf: function (oHotList_a) {
            var _this = this;
            var _Num = 0;
            var u = navigator.userAgent;
            //var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
            var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

            //检测室安卓还是ios
            if(u.search('origin/sfddjapp') > 0) {
                if(isIOS) {
                    _Num = 1;
                    oHotList_a.each(function(i) {
                        oHotList_a.eq(i).attr('href', _this.hrefName[_Num] + oHotList_a.eq(i).attr('_href')  )
                    })
                }
                else {
                    oHotList_a.each(function(i) {
                        _this.AndroidClick(oHotList_a.eq(i),oHotList_a.eq(i).attr('_href'))
                    })
                }
            }
            else {
                _Num = 0;
                oHotList_a.each(function(i) {
                    oHotList_a.eq(i).attr('href', _this.hrefName[_Num] + oHotList_a.eq(i).attr('_href')  )
                })
            }
        },
        AndroidClick: function (obj,arg) {
            obj.on('click',function() {
                android.goodsDetail(arg)
            })
        }
    }
});